home *** CD-ROM | disk | FTP | other *** search
- Path: pacific.st.usm.edu!not-for-mail
- From: mkirgan@pacific.st.usm.edu (Michael Kirgan)
- Newsgroups: comp.lang.c
- Subject: Return type - array of structures - please help!
- Date: 16 Apr 1996 14:53:36 GMT
- Organization: University of Southern Mississippi
- Message-ID: <4l0c9g$tsr@thorn.cc.usm.edu>
- NNTP-Posting-Host: ocean.st.usm.edu
- X-Newsreader: TIN [UNIX 1.3 950515BETA PL0]
-
- I wish to make the function called delete to return an array of
- structures or if that is not possible at least create it so when
- I pass an array of structures, it is by reference and not value like
- listed below.
-
- Here is an expample of my code:
-
- typdef struct
- {
- char ssn[12];
- char lastname[15];
- char firstname[15];
- char data[10];
- } student;
-
- void delete(char [], class [])
- {
- student temp[25];
- /*omitted the body. All it does is delete a struct from the array*/
- /*temp is the new array with the structure deleteted and it is copied
- /*back into students*/
-
-
- class = temp;
- }
-
- main()
- {
- student class[25];
-
- /*there is now a loop to read in the class info.*/
- /*next there is a loop to process options, such as printing out the
- contents of the class, searching for a student in class, deleting,
- & inserting*/
-
- /*I was currently calling delete like this:*/
- delete(delssn, class);
- }
-
-
- The above code works, but it passes by value, so changes are not passed back.
- Instead of trying to make it pass by reference I would just like functions
- such as delete & insert to return an array of structures.
-
- I have called delete like this:
-
- class = delete(delssn, class);
-
- The above should have the same effect as when I said: class = temp in the
- function delete, except I get it returned to main, however, this seems to
- give me an error. I am assuming I get this error, because I also
- get an error in the following function header or prototype, depending if
- I use a prototype or just list the function first:
-
-
- student [] delete(char delssn[], char class[]);
-
- Why does this not work? How am I supposed to set up a return type of an
- array of structures? Remember I have already done a typedef of student
- above, so refer to it to view the stucture.
-
- If anyone knows please help, this is the first program I have had trouble
- programming for my class & I don't want to turn it in to late. If you
- think it is easier to do by passing the array of structures by reference,
- then please specify how I would set up function header, prototypes, how
- would I call it & any other needed info.
-
-
- Thanks in advance,
-
-
-
- Mike
- mkirgan@ocean.st.usm.edu
-